package com.wind.easycode.common.base;

public class Paging {
	private int pageSize;
	private int pageNum;
	private long total;

	Paging() {
		this.pageNum = 1;
		this.pageSize = 10;

	}

	public Paging(int pageNum, int pageSize) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;

	}

	public Paging(int pageNum, int pageSize, long rowCount) {
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.total = rowCount;

	}

	public static Paging createPaging(Integer pageNum, Integer pageSize) {
		if (pageNum == null || pageNum < 1) {
			pageNum = 1;
		}
		if (pageSize == null || pageSize < 1) {
			pageSize = 10;
		}
		return new Paging(pageNum, pageSize);

	}

	public int getRowStart() {

		return (pageNum - 1) * pageSize;
	}

	public long getStartIndex() {

		return (pageNum - 1) * pageSize + 1;
	}

	public long getEndIndex() {

		return pageNum * pageSize;
	}

	public long getTotalPages() {
		if (total % pageSize == 0) {

			return pageNum / pageSize;
		}

		return pageNum / pageSize + 1;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNum() {
		return pageNum;
	}

	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}

	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

}
